2 if ( ! defined( 'MEDIAWIKI' ) )
12 require_once( 'Linker.php' );
13 require_once( 'Image.php' );
15 # Get a list of all skins available in /skins/
16 # Build using the regular expression '^(.*).php$'
17 # Array keys are all lower case, array value keep the case used by filename
20 $skinDir = dir($IP.'/skins');
22 # while code from www.php.net
23 while (false !== ($file = $skinDir->read())) {
24 // Skip non-PHP files, hidden files, and '.dep' includes
25 if(preg_match('/^([^.]*)\.php$/',$file, $matches)) {
27 $wgValidSkinNames[strtolower($aSkin)] = $aSkin;
34 * The main skin class that provide methods and properties for all other skins
35 * including PHPTal skins.
36 * This base class is also the "Standard" skin.
39 class Skin
extends Linker
{
43 var $lastdate, $lastline;
44 var $rc_cache ; # Cache for Enhanced Recent Changes
45 var $rcCacheIndex ; # Recent Changes Cache Counter for visibility toggle
49 /** Constructor, call parent constructor */
50 function Skin() { parent
::Linker(); }
53 * Fetch the set of available skins.
54 * @return array of strings
57 function getSkinNames() {
58 global $wgValidSkinNames;
59 return $wgValidSkinNames;
63 * Normalize a skin preference value to a form that can be loaded.
64 * If a skin can't be found, it will fall back to the configured
65 * default (or the old 'Classic' skin if that's broken).
70 function normalizeKey( $key ) {
71 global $wgDefaultSkin;
72 $skinNames = Skin
::getSkinNames();
75 // Don't return the default immediately;
76 // in a misconfiguration we need to fall back.
77 $key = $wgDefaultSkin;
80 if( isset( $skinNames[$key] ) ) {
84 // Older versions of the software used a numeric setting
85 // in the user preferences.
91 if( isset( $fallback[$key] ) ){
92 $key = $fallback[$key];
95 if( isset( $skinNames[$key] ) ) {
98 // The old built-in skin
104 * Factory method for loading a skin of a given type
105 * @param string $key 'monobook', 'standard', etc
109 function &newFromKey( $key ) {
110 $key = Skin
::normalizeKey( $key );
112 $skinNames = Skin
::getSkinNames();
113 $skinName = $skinNames[$key];
117 # Grab the skin class and initialise it. Each skin checks for PHPTal
118 # and will not load if it's not enabled.
119 wfSuppressWarnings();
120 // Preload base classes to work around APC/PHP5 bug
121 include_once( $IP.'/skins/'.$skinName.'.deps.php' );
123 require_once( $IP.'/skins/'.$skinName.'.php' );
125 # Check if we got if not failback to default skin
126 $className = 'Skin'.$skinName;
127 if( !class_exists( $className ) ) {
128 # DO NOT die if the class isn't found. This breaks maintenance
129 # scripts and can cause a user account to be unrecoverable
130 # except by SQL manipulation if a previously valid skin name
131 # is no longer valid.
132 $className = 'SkinStandard';
133 require_once( $IP.'/skins/Standard.php' );
135 $skin =& new $className;
139 /** @return string path to the skin stylesheet */
140 function getStylesheet() {
141 return 'common/wikistandard.css?1';
144 /** @return string skin name */
145 function getSkinName() {
149 function qbSetting() {
150 global $wgOut, $wgUser;
152 if ( $wgOut->isQuickbarSuppressed() ) { return 0; }
153 $q = $wgUser->getOption( 'quickbar' );
154 if ( '' == $q ) { $q = 0; }
158 function initPage( &$out ) {
161 $fname = 'Skin::initPage';
162 wfProfileIn( $fname );
164 if( false !== $wgFavicon ) {
165 $out->addLink( array( 'rel' => 'shortcut icon', 'href' => $wgFavicon ) );
168 $this->addMetadataLinks($out);
170 $this->mRevisionId
= $out->mRevisionId
;
172 wfProfileOut( $fname );
175 function addMetadataLinks( &$out ) {
176 global $wgTitle, $wgEnableDublinCoreRdf, $wgEnableCreativeCommonsRdf;
177 global $wgRightsPage, $wgRightsUrl;
179 if( $out->isArticleRelated() ) {
180 # note: buggy CC software only reads first "meta" link
181 if( $wgEnableCreativeCommonsRdf ) {
182 $out->addMetadataLink( array(
183 'title' => 'Creative Commons',
184 'type' => 'application/rdf+xml',
185 'href' => $wgTitle->getLocalURL( 'action=creativecommons') ) );
187 if( $wgEnableDublinCoreRdf ) {
188 $out->addMetadataLink( array(
189 'title' => 'Dublin Core',
190 'type' => 'application/rdf+xml',
191 'href' => $wgTitle->getLocalURL( 'action=dublincore' ) ) );
195 if( $wgRightsPage ) {
196 $copy = Title
::newFromText( $wgRightsPage );
198 $copyright = $copy->getLocalURL();
201 if( !$copyright && $wgRightsUrl ) {
202 $copyright = $wgRightsUrl;
205 $out->addLink( array(
206 'rel' => 'copyright',
207 'href' => $copyright ) );
211 function outputPage( &$out ) {
212 global $wgDebugComments;
214 wfProfileIn( 'Skin::outputPage' );
215 $this->initPage( $out );
217 $out->out( $out->headElement() );
219 $out->out( "\n<body" );
220 $ops = $this->getBodyOptions();
221 foreach ( $ops as $name => $val ) {
222 $out->out( " $name='$val'" );
225 if ( $wgDebugComments ) {
226 $out->out( "<!-- Wiki debugging output:\n" .
227 $out->mDebugtext
. "-->\n" );
230 $out->out( $this->beforeContent() );
232 $out->out( $out->mBodytext
. "\n" );
234 $out->out( $this->afterContent() );
236 $out->out( $out->reportTime() );
238 $out->out( "\n</body></html>" );
241 function getHeadScripts() {
242 global $wgStylePath, $wgUser, $wgAllowUserJs, $wgJsMimeType;
243 $r = "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/wikibits.js\"></script>\n";
244 if( $wgAllowUserJs && $wgUser->isLoggedIn() ) {
245 $userpage = $wgUser->getUserPage();
246 $userjs = htmlspecialchars( $this->makeUrl(
247 $userpage->getPrefixedText().'/'.$this->getSkinName().'.js',
248 'action=raw&ctype='.$wgJsMimeType));
249 $r .= '<script type="'.$wgJsMimeType.'" src="'.$userjs."\"></script>\n";
255 * To make it harder for someone to slip a user a fake
256 * user-JavaScript or user-CSS preview, a random token
257 * is associated with the login session. If it's not
258 * passed back with the preview request, we won't render
261 * @param string $action
265 function userCanPreview( $action ) {
266 global $wgTitle, $wgRequest, $wgUser;
268 if( $action != 'submit' )
270 if( !$wgRequest->wasPosted() )
272 if( !$wgTitle->userCanEditCssJsSubpage() )
274 return $wgUser->matchEditToken(
275 $wgRequest->getVal( 'wpEditToken' ) );
278 # get the user/site-specific stylesheet, SkinPHPTal called from RawPage.php (settings are cached that way)
279 function getUserStylesheet() {
280 global $wgOut, $wgStylePath, $wgRequest, $wgContLang, $wgSquidMaxage;
281 $sheet = $this->getStylesheet();
282 $action = $wgRequest->getText('action');
283 $s = "@import \"$wgStylePath/$sheet\";\n";
284 if($wgContLang->isRTL()) $s .= "@import \"$wgStylePath/common/common_rtl.css\";\n";
286 $query = "action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
287 $s .= '@import "' . $this->makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI
) . "\";\n" .
288 '@import "'.$this->makeNSUrl( ucfirst( $this->getSkinName() . '.css' ), $query, NS_MEDIAWIKI
) . "\";\n";
290 $s .= $this->doGetUserStyles();
295 * placeholder, returns generated js in monobook
297 function getUserJs() { return; }
300 * Return html code that include User stylesheets
302 function getUserStyles() {
303 global $wgOut, $wgStylePath;
304 $s = "<style type='text/css'>\n";
305 $s .= "/*/*/ /*<![CDATA[*/\n"; # <-- Hide the styles from Netscape 4 without hiding them from IE/Mac
306 $s .= $this->getUserStylesheet();
307 $s .= "/*]]>*/ /* */\n";
313 * Some styles that are set by user through the user settings interface.
315 function doGetUserStyles() {
316 global $wgUser, $wgContLang, $wgUser, $wgRequest, $wgTitle, $wgAllowUserCss;
320 if( $wgAllowUserCss && $wgUser->isLoggedIn() ) { # logged in
321 if($wgTitle->isCssSubpage() && $this->userCanPreview( $action ) ) {
322 $s .= $wgRequest->getText('wpTextbox1');
324 $userpage = $wgUser->getUserPage();
325 $s.= '@import "'.$this->makeUrl(
326 $userpage->getPrefixedText().'/'.$this->getSkinName().'.css',
327 'action=raw&ctype=text/css').'";'."\n";
331 return $s . $this->reallyDoGetUserStyles();
334 function reallyDoGetUserStyles() {
337 if (($undopt = $wgUser->getOption("underline")) != 2) {
338 $underline = $undopt ?
'underline' : 'none';
339 $s .= "a { text-decoration: $underline; }\n";
341 if( $wgUser->getOption( 'highlightbroken' ) ) {
342 $s .= "a.new, #quickbar a.new { color: #CC2200; }\n";
345 a.new, #quickbar a.new,
346 a.stub, #quickbar a.stub {
348 text-decoration: inherit;
350 a.new:after, #quickbar a.new:after {
353 text-decoration: $underline;
355 a.stub:after, #quickbar a.stub:after {
358 text-decoration: $underline;
362 if( $wgUser->getOption( 'justify' ) ) {
363 $s .= "#article, #bodyContent { text-align: justify; }\n";
365 if( !$wgUser->getOption( 'showtoc' ) ) {
366 $s .= "#toc { display: none; }\n";
368 if( !$wgUser->getOption( 'editsection' ) ) {
369 $s .= ".editsection { display: none; }\n";
374 function getBodyOptions() {
375 global $wgUser, $wgTitle, $wgOut, $wgRequest;
377 extract( $wgRequest->getValues( 'oldid', 'redirect', 'diff' ) );
379 if ( 0 != $wgTitle->getNamespace() ) {
380 $a = array( 'bgcolor' => '#ffffec' );
382 else $a = array( 'bgcolor' => '#FFFFFF' );
383 if($wgOut->isArticle() && $wgUser->getOption('editondblclick') &&
384 $wgTitle->userCanEdit() ) {
385 $t = wfMsg( 'editthispage' );
386 $s = $wgTitle->getFullURL( $this->editUrlOptions() );
387 $s = 'document.location = "' .wfEscapeJSString( $s ) .'";';
388 $a +
= array ('ondblclick' => $s);
391 $a['onload'] = $wgOut->getOnloadHandler();
392 if( $wgUser->getOption( 'editsectiononrightclick' ) ) {
393 if( $a['onload'] != '' ) {
396 $a['onload'] .= 'setupRightClickEdit()';
410 * This will be called immediately after the <body> tag. Split into
411 * two functions to make it easier to subclass.
413 function beforeContent() {
414 return $this->doBeforeContent();
417 function doBeforeContent() {
418 global $wgOut, $wgTitle, $wgContLang;
419 $fname = 'Skin::doBeforeContent';
420 wfProfileIn( $fname );
423 $qb = $this->qbSetting();
425 if( $langlinks = $this->otherLanguages() ) {
431 $borderhack = 'class="top"';
434 $s .= "\n<div id='content'>\n<div id='topbar'>\n" .
435 "<table border='0' cellspacing='0' width='98%'>\n<tr>\n";
438 $left = ($qb == 1 ||
$qb == 3);
439 if($wgContLang->isRTL()) $left = !$left;
442 $s .= "<td class='top' align='left' valign='top' rowspan='{$rows}'>\n" .
443 $this->logoText() . '</td>';
445 $s .= $this->getQuickbarCompensator( $rows );
447 $l = $wgContLang->isRTL() ?
'right' : 'left';
448 $s .= "<td {$borderhack} align='$l' valign='top'>\n";
450 $s .= $this->topLinks() ;
451 $s .= "<p class='subtitle'>" . $this->pageTitleLinks() . "</p>\n";
453 $r = $wgContLang->isRTL() ?
"left" : "right";
454 $s .= "</td>\n<td {$borderhack} valign='top' align='$r' nowrap='nowrap'>";
455 $s .= $this->nameAndLogin();
456 $s .= "\n<br />" . $this->searchForm() . "</td>";
459 $s .= "</tr>\n<tr>\n<td class='top' colspan=\"2\">$langlinks</td>\n";
462 if ( $shove && !$left ) { # Right
463 $s .= $this->getQuickbarCompensator( $rows );
465 $s .= "</tr>\n</table>\n</div>\n";
466 $s .= "\n<div id='article'>\n";
468 $notice = wfGetSiteNotice();
470 $s .= "\n<div id='siteNotice'>$notice</div>\n";
472 $s .= $this->pageTitle();
473 $s .= $this->pageSubtitle() ;
474 $s .= $this->getCategories();
475 wfProfileOut( $fname );
480 function getCategoryLinks () {
481 global $wgOut, $wgTitle, $wgUseCategoryBrowser;
484 if( count( $wgOut->mCategoryLinks
) == 0 ) return '';
486 // Use Unicode bidi embedding override characters,
487 // to make sure links don't smash each other up in ugly ways.
488 $dir = $wgContLang->isRTL() ?
'rtl' : 'ltr';
489 $embed = "<span dir='$dir'>";
491 $t = $embed . implode ( "$pop | $embed" , $wgOut->mCategoryLinks
) . $pop;
493 $msg = count( $wgOut->mCategoryLinks
) === 1 ?
'categories1' : 'categories';
494 $s = $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Categories' ),
495 wfMsg( $msg ), 'article=' . urlencode( $wgTitle->getPrefixedDBkey() ) )
498 # optional 'dmoz-like' category browser. Will be shown under the list
499 # of categories an article belong to
500 if($wgUseCategoryBrowser) {
501 $s .= '<br /><hr />';
503 # get a big array of the parents tree
504 $parenttree = $wgTitle->getParentCategoryTree();
505 # Skin object passed by reference cause it can not be
506 # accessed under the method subfunction drawCategoryBrowser
507 $tempout = explode("\n", Skin
::drawCategoryBrowser($parenttree, $this) );
508 # Clean out bogus first entry and sort them
511 # Output one per line
512 $s .= implode("<br />\n", $tempout);
518 /** Render the array as a serie of links.
519 * @param array $tree Categories tree returned by Title::getParentCategoryTree
520 * @param object &skin Skin passed by reference
521 * @return string separated by >, terminate with "\n"
523 function drawCategoryBrowser($tree, &$skin) {
525 foreach ($tree as $element => $parent) {
526 if (empty($parent)) {
527 # element start a new list
530 # grab the others elements
531 $return .= Skin
::drawCategoryBrowser($parent, $skin) . ' > ';
533 # add our current element to the list
534 $eltitle = Title
::NewFromText($element);
535 $return .= $skin->makeLinkObj( $eltitle, $eltitle->getText() ) ;
540 function getCategories() {
541 $catlinks=$this->getCategoryLinks();
542 if(!empty($catlinks)) {
543 return "<p class='catlinks'>{$catlinks}</p>";
547 function getQuickbarCompensator( $rows = 1 ) {
548 return "<td width='152' rowspan='{$rows}'> </td>";
552 * This gets called immediately before the </body> tag.
553 * @return string HTML to be put after </body> ???
555 function afterContent() {
556 $printfooter = "<div class=\"printfooter\">\n" . $this->printFooter() . "</div>\n";
557 return $printfooter . $this->doAfterContent();
560 /** @return string Retrievied from HTML text */
561 function printSource() {
563 $url = htmlspecialchars( $wgTitle->getFullURL() );
564 return wfMsg( 'retrievedfrom', '<a href="'.$url.'">'.$url.'</a>' );
567 function printFooter() {
568 return "<p>" . $this->printSource() .
569 "</p>\n\n<p>" . $this->pageStats() . "</p>\n";
572 /** overloaded by derived classes */
573 function doAfterContent() { }
575 function pageTitleLinks() {
576 global $wgOut, $wgTitle, $wgUser, $wgContLang, $wgRequest;
578 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
579 $action = $wgRequest->getText( 'action' );
581 $s = $this->printableLink();
582 $disclaimer = $this->disclaimerLink(); # may be empty
584 $s .= ' | ' . $disclaimer;
586 $privacy = $this->privacyLink(); # may be empty too
588 $s .= ' | ' . $privacy;
591 if ( $wgOut->isArticleRelated() ) {
592 if ( $wgTitle->getNamespace() == NS_IMAGE
) {
593 $name = $wgTitle->getDBkey();
594 $image = new Image( $wgTitle );
595 if( $image->exists() ) {
596 $link = htmlspecialchars( $image->getURL() );
597 $style = $this->getInternalLinkAttributes( $link, $name );
598 $s .= " | <a href=\"{$link}\"{$style}>{$name}</a>";
602 if ( 'history' == $action ||
isset( $diff ) ||
isset( $oldid ) ) {
603 $s .= ' | ' . $this->makeKnownLinkObj( $wgTitle,
604 wfMsg( 'currentrev' ) );
607 if ( $wgUser->getNewtalk() ) {
608 # do not show "You have new messages" text when we are viewing our
610 if( !$wgTitle->equals( $wgUser->getTalkPage() ) ) {
611 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessageslink' ) );
612 $dl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessagesdifflink' ), 'diff=cur' );
613 $s.= ' | <strong>'. wfMsg( 'youhavenewmessages', $tl, $dl ) . '</strong>';
615 $wgOut->setSquidMaxage(0);
616 $wgOut->enableClientCache(false);
620 $undelete = $this->getUndeleteLink();
621 if( !empty( $undelete ) ) {
622 $s .= ' | '.$undelete;
627 function getUndeleteLink() {
628 global $wgUser, $wgTitle, $wgContLang, $action;
629 if( $wgUser->isAllowed( 'deletedhistory' ) &&
630 (($wgTitle->getArticleId() == 0) ||
($action == "history")) &&
631 ($n = $wgTitle->isDeleted() ) )
633 if ( $wgUser->isAllowed( 'delete' ) ) {
634 $msg = 'thisisdeleted';
636 $msg = 'viewdeleted';
639 $this->makeKnownLink(
640 $wgContLang->SpecialPage( 'Undelete/' . $wgTitle->getPrefixedDBkey() ),
641 wfMsg( 'restorelink' . ($n == 1 ?
'1' : ''), $n ) ) );
646 function printableLink() {
647 global $wgOut, $wgFeedClasses, $wgRequest;
649 $baseurl = $_SERVER['REQUEST_URI'];
650 if( strpos( '?', $baseurl ) == false ) {
655 $baseurl = htmlspecialchars( $baseurl );
656 $printurl = $wgRequest->escapeAppendQuery( 'printable=yes' );
658 $s = "<a href=\"$printurl\">" . wfMsg( 'printableversion' ) . '</a>';
659 if( $wgOut->isSyndicated() ) {
660 foreach( $wgFeedClasses as $format => $class ) {
661 $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" );
662 $s .= " | <a href=\"$feedurl\">{$format}</a>";
668 function pageTitle() {
669 global $wgOut, $wgTitle, $wgUser;
671 $s = '<h1 class="pagetitle">' . htmlspecialchars( $wgOut->getPageTitle() ) . '</h1>';
675 function pageSubtitle() {
678 $sub = $wgOut->getSubtitle();
680 global $wgExtraSubtitle;
681 $sub = wfMsg( 'tagline' ) . $wgExtraSubtitle;
683 $subpages = $this->subPageSubtitle();
684 $sub .= !empty($subpages)?
"</p><p class='subpages'>$subpages":'';
685 $s = "<p class='subtitle'>{$sub}</p>\n";
689 function subPageSubtitle() {
690 global $wgOut,$wgTitle,$wgNamespacesWithSubpages;
692 if($wgOut->isArticle() && !empty($wgNamespacesWithSubpages[$wgTitle->getNamespace()])) {
693 $ptext=$wgTitle->getPrefixedText();
694 if(preg_match('/\//',$ptext)) {
695 $links = explode('/',$ptext);
698 foreach($links as $link) {
700 if ($c<count($links)) {
701 $growinglink .= $link;
702 $getlink = $this->makeLink( $growinglink, $link );
703 if(preg_match('/class="new"/i',$getlink)) { break; } # this is a hack, but it saves time
707 $subpages .= '< ';
709 $subpages .= $getlink;
718 function nameAndLogin() {
719 global $wgUser, $wgTitle, $wgLang, $wgContLang, $wgShowIPinHeader;
721 $li = $wgContLang->specialPage( 'Userlogin' );
722 $lo = $wgContLang->specialPage( 'Userlogout' );
725 if ( $wgUser->isAnon() ) {
726 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get('session.name')] ) ) {
729 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
730 $wgLang->getNsText( NS_TALK
) );
732 $s .= $n . ' ('.$tl.')';
734 $s .= wfMsg('notloggedin');
737 $rt = $wgTitle->getPrefixedURL();
738 if ( 0 == strcasecmp( urlencode( $lo ), $rt ) ) {
740 } else { $q = "returnto={$rt}"; }
742 $s .= "\n<br />" . $this->makeKnownLinkObj(
743 Title
::makeTitle( NS_SPECIAL
, 'Userlogin' ),
744 wfMsg( 'login' ), $q );
746 $n = $wgUser->getName();
747 $rt = $wgTitle->getPrefixedURL();
748 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
749 $wgLang->getNsText( NS_TALK
) );
753 $s .= $this->makeKnownLinkObj( $wgUser->getUserPage(),
754 $n ) . "{$tl}<br />" .
755 $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Userlogout' ), wfMsg( 'logout' ),
756 "returnto={$rt}" ) . ' | ' .
757 $this->specialLink( 'preferences' );
759 $s .= ' | ' . $this->makeKnownLink( wfMsgForContent( 'helppage' ),
765 function getSearchLink() {
766 $searchPage =& Title
::makeTitle( NS_SPECIAL
, 'Search' );
767 return $searchPage->getLocalURL();
770 function escapeSearchLink() {
771 return htmlspecialchars( $this->getSearchLink() );
774 function searchForm() {
776 $search = $wgRequest->getText( 'search' );
778 $s = '<form name="search" class="inline" method="post" action="'
779 . $this->escapeSearchLink() . "\">\n"
780 . '<input type="text" name="search" size="19" value="'
781 . htmlspecialchars(substr($search,0,256)) . "\" />\n"
782 . '<input type="submit" name="go" value="' . wfMsg ('go') . '" /> '
783 . '<input type="submit" name="fulltext" value="' . wfMsg ('search') . "\" />\n</form>";
788 function topLinks() {
792 $s = $this->mainPageLink() . $sep
793 . $this->specialLink( 'recentchanges' );
795 if ( $wgOut->isArticleRelated() ) {
796 $s .= $sep . $this->editThisPage()
797 . $sep . $this->historyLink();
799 # Many people don't like this dropdown box
800 #$s .= $sep . $this->specialPagesList();
802 /* show links to different language variants */
803 global $wgDisableLangConversion, $wgContLang, $wgTitle;
804 $variants = $wgContLang->getVariants();
805 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
806 foreach( $variants as $code ) {
807 $varname = $wgContLang->getVariantname( $code );
808 if( $varname == 'disable' )
810 $s .= ' | <a href="' . $wgTitle->getLocalUrl( 'variant=' . $code ) . '">' . $varname . '</a>';
817 function bottomLinks() {
818 global $wgOut, $wgUser, $wgTitle, $wgUseTrackbacks;
822 if ( $wgOut->isArticleRelated() ) {
823 $s .= '<strong>' . $this->editThisPage() . '</strong>';
824 if ( $wgUser->isLoggedIn() ) {
825 $s .= $sep . $this->watchThisPage();
827 $s .= $sep . $this->talkLink()
828 . $sep . $this->historyLink()
829 . $sep . $this->whatLinksHere()
830 . $sep . $this->watchPageLinksLink();
832 if ($wgUseTrackbacks)
833 $s .= $sep . $this->trackbackLink();
835 if ( $wgTitle->getNamespace() == NS_USER
836 ||
$wgTitle->getNamespace() == NS_USER_TALK
)
839 $id=User
::idFromName($wgTitle->getText());
840 $ip=User
::isIP($wgTitle->getText());
842 if($id ||
$ip) { # both anons and non-anons have contri list
843 $s .= $sep . $this->userContribsLink();
845 if( $this->showEmailUser( $id ) ) {
846 $s .= $sep . $this->emailUserLink();
849 if ( $wgTitle->getArticleId() ) {
851 if($wgUser->isAllowed('delete')) { $s .= $this->deleteThisPage(); }
852 if($wgUser->isAllowed('protect')) { $s .= $sep . $this->protectThisPage(); }
853 if($wgUser->isAllowed('move')) { $s .= $sep . $this->moveThisPage(); }
855 $s .= "<br />\n" . $this->otherLanguages();
860 function pageStats() {
861 global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
862 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgTitle, $wgPageShowWatchingUsers;
864 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
865 if ( ! $wgOut->isArticle() ) { return ''; }
866 if ( isset( $oldid ) ||
isset( $diff ) ) { return ''; }
867 if ( 0 == $wgArticle->getID() ) { return ''; }
870 if ( !$wgDisableCounters ) {
871 $count = $wgLang->formatNum( $wgArticle->getCount() );
873 $s = wfMsg( 'viewcount', $count );
877 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
878 require_once('Credits.php');
879 $s .= ' ' . getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
881 $s .= $this->lastModified();
884 if ($wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
885 $dbr =& wfGetDB( DB_SLAVE
);
886 extract( $dbr->tableNames( 'watchlist' ) );
887 $sql = "SELECT COUNT(*) AS n FROM $watchlist
888 WHERE wl_title='" . $dbr->strencode($wgTitle->getDBKey()) .
889 "' AND wl_namespace=" . $wgTitle->getNamespace() ;
890 $res = $dbr->query( $sql, 'Skin::pageStats');
891 $x = $dbr->fetchObject( $res );
892 $s .= ' ' . wfMsg('number_of_watching_users_pageview', $x->n
);
895 return $s . ' ' . $this->getCopyright();
898 function getCopyright() {
899 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest;
902 $oldid = $wgRequest->getVal( 'oldid' );
903 $diff = $wgRequest->getVal( 'diff' );
905 if ( !is_null( $oldid ) && is_null( $diff ) && wfMsgForContent( 'history_copyright' ) !== '-' ) {
906 $msg = 'history_copyright';
912 if( $wgRightsPage ) {
913 $link = $this->makeKnownLink( $wgRightsPage, $wgRightsText );
914 } elseif( $wgRightsUrl ) {
915 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
920 $out .= wfMsgForContent( $msg, $link );
924 function getCopyrightIcon() {
925 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
927 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
928 $out = $wgCopyrightIcon;
929 } else if ( $wgRightsIcon ) {
930 $icon = htmlspecialchars( $wgRightsIcon );
931 if ( $wgRightsUrl ) {
932 $url = htmlspecialchars( $wgRightsUrl );
933 $out .= '<a href="'.$url.'">';
935 $text = htmlspecialchars( $wgRightsText );
936 $out .= "<img src=\"$icon\" alt='$text' />";
937 if ( $wgRightsUrl ) {
944 function getPoweredBy() {
946 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
947 $img = '<a href="http://www.mediawiki.org/"><img src="'.$url.'" alt="MediaWiki" /></a>';
951 function lastModified() {
952 global $wgLang, $wgArticle, $wgLoadBalancer;
954 $timestamp = $wgArticle->getTimestamp();
956 $d = $wgLang->timeanddate( $timestamp, true );
957 $s = ' ' . wfMsg( 'lastmodified', $d );
961 if ( $wgLoadBalancer->getLaggedSlaveMode() ) {
962 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
967 function logoText( $align = '' ) {
968 if ( '' != $align ) { $a = " align='{$align}'"; }
971 $mp = wfMsg( 'mainpage' );
972 $titleObj = Title
::newFromText( $mp );
973 if ( is_object( $titleObj ) ) {
974 $url = $titleObj->escapeLocalURL();
979 $logourl = $this->getLogo();
980 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
985 * show a drop-down box of special pages
986 * @TODO crash bug913. Need to be rewrote completly.
988 function specialPagesList() {
989 global $wgUser, $wgOut, $wgContLang, $wgServer, $wgRedirectScript, $wgAvailableRights;
990 require_once('SpecialPage.php');
992 $pages = SpecialPage
::getPages();
994 // special pages without access restriction
995 foreach ( $pages[''] as $name => $page ) {
996 $a[$name] = $page->getDescription();
999 // Other special pages that are restricted.
1000 // Copied from SpecialSpecialpages.php
1001 foreach($wgAvailableRights as $right) {
1002 if( $wgUser->isAllowed($right) ) {
1003 /** Add all pages for this right */
1004 if(isset($pages[$right])) {
1005 foreach($pages[$right] as $name => $page) {
1006 $a[$name] = $page->getDescription();
1012 $go = wfMsg( 'go' );
1013 $sp = wfMsg( 'specialpages' );
1014 $spp = $wgContLang->specialPage( 'Specialpages' );
1016 $s = '<form id="specialpages" method="get" class="inline" ' .
1017 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
1018 $s .= "<select name=\"wpDropdown\">\n";
1019 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
1022 foreach ( $a as $name => $desc ) {
1023 $p = $wgContLang->specialPage( $name );
1024 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
1026 $s .= "</select>\n";
1027 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
1032 function mainPageLink() {
1033 $mp = wfMsgForContent( 'mainpage' );
1034 $mptxt = wfMsg( 'mainpage');
1035 $s = $this->makeKnownLink( $mp, $mptxt );
1039 function copyrightLink() {
1040 $s = $this->makeKnownLink( wfMsgForContent( 'copyrightpage' ),
1041 wfMsg( 'copyrightpagename' ) );
1045 function privacyLink() {
1046 $privacy = wfMsg( 'privacy' );
1047 if ($privacy == '-') {
1050 return $this->makeKnownLink( wfMsgForContent( 'privacypage' ), $privacy);
1054 function aboutLink() {
1055 $s = $this->makeKnownLink( wfMsgForContent( 'aboutpage' ),
1056 wfMsg( 'aboutsite' ) );
1060 function disclaimerLink() {
1061 $disclaimers = wfMsg( 'disclaimers' );
1062 if ($disclaimers == '-') {
1065 return $this->makeKnownLink( wfMsgForContent( 'disclaimerpage' ),
1070 function editThisPage() {
1071 global $wgOut, $wgTitle, $wgRequest;
1073 if ( ! $wgOut->isArticleRelated() ) {
1074 $s = wfMsg( 'protectedpage' );
1076 if ( $wgTitle->userCanEdit() ) {
1077 $t = wfMsg( 'editthispage' );
1079 $t = wfMsg( 'viewsource' );
1082 $s = $this->makeKnownLinkObj( $wgTitle, $t, $this->editUrlOptions() );
1088 * Return URL options for the 'edit page' link.
1089 * This may include an 'oldid' specifier, if the current page view is such.
1094 function editUrlOptions() {
1097 if( $this->mRevisionId
&& ! $wgArticle->isCurrent() ) {
1098 return "action=edit&oldid=" . intval( $this->mRevisionId
);
1100 return "action=edit";
1104 function deleteThisPage() {
1105 global $wgUser, $wgOut, $wgTitle, $wgRequest;
1107 $diff = $wgRequest->getVal( 'diff' );
1108 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('delete') ) {
1109 $t = wfMsg( 'deletethispage' );
1111 $s = $this->makeKnownLinkObj( $wgTitle, $t, 'action=delete' );
1118 function protectThisPage() {
1119 global $wgUser, $wgOut, $wgTitle, $wgRequest;
1121 $diff = $wgRequest->getVal( 'diff' );
1122 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) {
1123 if ( $wgTitle->isProtected() ) {
1124 $t = wfMsg( 'unprotectthispage' );
1125 $q = 'action=unprotect';
1127 $t = wfMsg( 'protectthispage' );
1128 $q = 'action=protect';
1130 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
1137 function watchThisPage() {
1138 global $wgUser, $wgOut, $wgTitle;
1140 if ( $wgOut->isArticleRelated() ) {
1141 if ( $wgTitle->userIsWatching() ) {
1142 $t = wfMsg( 'unwatchthispage' );
1143 $q = 'action=unwatch';
1145 $t = wfMsg( 'watchthispage' );
1146 $q = 'action=watch';
1148 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
1150 $s = wfMsg( 'notanarticle' );
1155 function moveThisPage() {
1158 if ( $wgTitle->userCanMove() ) {
1159 return $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Movepage' ),
1160 wfMsg( 'movethispage' ), 'target=' . $wgTitle->getPrefixedURL() );
1162 // no message if page is protected - would be redundant
1167 function historyLink() {
1170 return $this->makeKnownLinkObj( $wgTitle,
1171 wfMsg( 'history' ), 'action=history' );
1174 function whatLinksHere() {
1177 return $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Whatlinkshere' ),
1178 wfMsg( 'whatlinkshere' ), 'target=' . $wgTitle->getPrefixedURL() );
1181 function userContribsLink() {
1184 return $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Contributions' ),
1185 wfMsg( 'contributions' ), 'target=' . $wgTitle->getPartialURL() );
1188 function showEmailUser( $id ) {
1189 global $wgEnableEmail, $wgEnableUserEmail, $wgUser;
1190 return $wgEnableEmail &&
1191 $wgEnableUserEmail &&
1192 $wgUser->isLoggedIn() && # show only to signed in users
1193 0 != $id; # we can only email to non-anons ..
1194 # '' != $id->getEmail() && # who must have an email address stored ..
1195 # 0 != $id->getEmailauthenticationtimestamp() && # .. which is authenticated
1196 # 1 != $wgUser->getOption('disablemail'); # and not disabled
1199 function emailUserLink() {
1202 return $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Emailuser' ),
1203 wfMsg( 'emailuser' ), 'target=' . $wgTitle->getPartialURL() );
1206 function watchPageLinksLink() {
1207 global $wgOut, $wgTitle;
1209 if ( ! $wgOut->isArticleRelated() ) {
1210 return '(' . wfMsg( 'notanarticle' ) . ')';
1212 return $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
,
1213 'Recentchangeslinked' ), wfMsg( 'recentchangeslinked' ),
1214 'target=' . $wgTitle->getPrefixedURL() );
1218 function trackbackLink() {
1221 return "<a href=\"" . $wgTitle->trackbackURL() . "\">"
1222 . wfMsg('trackbacklink') . "</a>";
1225 function otherLanguages() {
1226 global $wgOut, $wgContLang, $wgTitle, $wgHideInterlanguageLinks;
1228 if ( $wgHideInterlanguageLinks ) {
1232 $a = $wgOut->getLanguageLinks();
1233 if ( 0 == count( $a ) ) {
1237 $s = wfMsg( 'otherlanguages' ) . ': ';
1239 if($wgContLang->isRTL()) $s .= '<span dir="LTR">';
1240 foreach( $a as $l ) {
1241 if ( ! $first ) { $s .= ' | '; }
1244 $nt = Title
::newFromText( $l );
1245 $url = $nt->escapeFullURL();
1246 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
1248 if ( '' == $text ) { $text = $l; }
1249 $style = $this->getExternalLinkAttributes( $l, $text );
1250 $s .= "<a href=\"{$url}\"{$style}>{$text}</a>";
1252 if($wgContLang->isRTL()) $s .= '</span>';
1256 function bugReportsLink() {
1257 $s = $this->makeKnownLink( wfMsgForContent( 'bugreportspage' ),
1258 wfMsg( 'bugreports' ) );
1262 function dateLink() {
1263 $t1 = Title
::newFromText( gmdate( 'F j' ) );
1264 $t2 = Title
::newFromText( gmdate( 'Y' ) );
1266 $id = $t1->getArticleID();
1269 $s = $this->makeBrokenLink( $t1->getText() );
1271 $s = $this->makeKnownLink( $t1->getText() );
1275 $id = $t2->getArticleID();
1278 $s .= $this->makeBrokenLink( $t2->getText() );
1280 $s .= $this->makeKnownLink( $t2->getText() );
1285 function talkLink() {
1288 if ( NS_SPECIAL
== $wgTitle->getNamespace() ) {
1289 # No discussion links for special pages
1293 if( $wgTitle->isTalkPage() ) {
1294 $link = $wgTitle->getSubjectPage();
1295 switch( $link->getNamespace() ) {
1297 $text = wfMsg('articlepage');
1300 $text = wfMsg('userpage');
1303 $text = wfMsg('wikipediapage');
1306 $text = wfMsg('imagepage');
1309 $text= wfMsg('articlepage');
1312 $link = $wgTitle->getTalkPage();
1313 $text = wfMsg( 'talkpage' );
1316 $s = $this->makeLinkObj( $link, $text );
1321 function commentLink() {
1322 global $wgContLang, $wgTitle;
1324 if ( $wgTitle->getNamespace() == NS_SPECIAL
) {
1327 return $this->makeKnownLinkObj( $wgTitle->getTalkPage(),
1328 wfMsg( 'postcomment' ), 'action=edit§ion=new' );
1331 /* these are used extensively in SkinPHPTal, but also some other places */
1332 /*static*/ function makeSpecialUrl( $name, $urlaction='' ) {
1333 $title = Title
::makeTitle( NS_SPECIAL
, $name );
1334 return $title->getLocalURL( $urlaction );
1337 /*static*/ function makeI18nUrl ( $name, $urlaction='' ) {
1338 $title = Title
::newFromText( wfMsgForContent($name) );
1339 $this->checkTitle($title, $name);
1340 return $title->getLocalURL( $urlaction );
1343 /*static*/ function makeUrl ( $name, $urlaction='' ) {
1344 $title = Title
::newFromText( $name );
1345 $this->checkTitle($title, $name);
1346 return $title->getLocalURL( $urlaction );
1349 # If url string starts with http, consider as external URL, else
1351 /*static*/ function makeInternalOrExternalUrl( $name ) {
1352 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
1355 return $this->makeUrl( $name );
1359 # this can be passed the NS number as defined in Language.php
1360 /*static*/ function makeNSUrl( $name, $urlaction='', $namespace=NS_MAIN
) {
1361 $title = Title
::makeTitleSafe( $namespace, $name );
1362 $this->checkTitle($title, $name);
1363 return $title->getLocalURL( $urlaction );
1366 /* these return an array with the 'href' and boolean 'exists' */
1367 /*static*/ function makeUrlDetails ( $name, $urlaction='' ) {
1368 $title = Title
::newFromText( $name );
1369 $this->checkTitle($title, $name);
1371 'href' => $title->getLocalURL( $urlaction ),
1372 'exists' => $title->getArticleID() != 0?
true:false
1377 * Make URL details where the article exists (or at least it's convenient to think so)
1379 function makeKnownUrlDetails( $name, $urlaction='' ) {
1380 $title = Title
::newFromText( $name );
1381 $this->checkTitle($title, $name);
1383 'href' => $title->getLocalURL( $urlaction ),
1388 # make sure we have some title to operate on
1389 /*static*/ function checkTitle ( &$title, &$name ) {
1390 if(!is_object($title)) {
1391 $title = Title
::newFromText( $name );
1392 if(!is_object($title)) {
1393 $title = Title
::newFromText( '--error: link target missing--' );
1399 * Build an array that represents the sidebar(s), the navigation bar among them
1404 function buildSidebar() {
1405 global $wgTitle, $action, $wgDBname, $parserMemc;
1406 global $wgLanguageCode, $wgContLanguageCode;
1408 $fname = 'SkinTemplate::buildSidebar';
1410 wfProfileIn( $fname );
1412 if ($wgLanguageCode == $wgContLanguageCode)
1413 $cacheSidebar = true;
1415 $cacheSidebar = false;
1417 if ($cacheSidebar) {
1418 $cachedsidebar=$parserMemc->get("{$wgDBname}:sidebar");
1419 if ($cachedsidebar!="") {
1420 wfProfileOut($fname);
1421 return $cachedsidebar;
1426 $lines = explode( "\n", wfMsgForContent( 'sidebar' ) );
1427 foreach ($lines as $line) {
1428 if (strpos($line, '*') !== 0)
1430 if (strpos($line, '**') !== 0) {
1431 $line = trim($line, '* ');
1434 if (strpos($line, '|') !== false) { // sanity check
1435 $line = explode( '|' , trim($line, '* '), 2 );
1436 $link = wfMsgForContent( $line[0] );
1439 if (wfEmptyMsg($line[1], $text = wfMsg($line[1])))
1441 if (wfEmptyMsg($line[0], $link))
1443 $href = $this->makeInternalOrExternalUrl( $link );
1444 $bar[$heading][] = array(
1447 'id' => 'n-' . strtr($line[1], ' ', '-'),
1450 } else { continue; }
1454 $cachednotice=$parserMemc->set("{$wgDBname}:sidebar",$bar,86400);
1455 wfProfileOut( $fname );